<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>{$title}</title>
    <script src="https://code.jquery.com/jquery-3.0.0.min.js"></script>
</head>
<body>
<div>
    <form class="registerform" method="post" id="regisertform" >
        用 &nbsp;户 &nbsp;名:<input type="text" id="username" name="username">*<br>
        密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码:<input type="password"id="password" name="password">*<br>
        确认密码:<input type="password" id="rpassword" name="rpassword">*<br>
        邮&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;箱:<input type="text"id="email" name="email">*<br>
        手 &nbsp;机 &nbsp;号:<input type="number" id="phone" name="phone">*<br>
            <input  class="register" type="button" value="{$b}" id="regisert">


    </form>

</div>


</body>
<script>

$(".register").click(function(){
    var email_exg=/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
    var username=$("#username").val();
    var password=$("#password").val();
    var rpassword=$("#rpassword").val();
    var email=$("#email").val();
    var phone=$("#phone").val();
    if(username=="" || username==null){
        alert('用户名不能为空');
        $("#username").focus();
        return false;
    }
    if(password=="" || password==null){
        alert("密码不能为空");
        $("#password").focus();
        return false;
    }
    if(rpassword!=password){
        alert("两次密码不一致");
        return false;
    }
    if(email==""||email==null){
        alert ("邮箱不能为空");
        $("#email").focus();
        return false;
    }
    if(!email_exg.test(email)){
        alert("邮箱格式不正确");
        $("#email").focus();
        return false;
    }
    if(phone=="" || phone==null){
        alert("手机号不能为空");
        $("#phone").focus();
        return false;

    }

    $.ajax({
        url:'/index/adduser',
        data:{'username':username,'password':password,'email':email,'phone':phone},
        dataType:'json',
        async:false,
        type:'post',
        success:function(data){
            if(data.status==1){
                alert('注册成功');
                window.location.href='/index/login';
            }else{
                alert('用户信息已存在');
                return false;
            }
        }

    })
});
</script>
</html>